#ifndef _TGAutoClose_H_
#define _TGAutoClose_H_

#include "winsock2.h"

struct TG_AUTO_CLOSESOCKET
{
	TG_AUTO_CLOSESOCKET(SOCKET *pSocket)
	{
		m_pSocket = pSocket;
	}
	~TG_AUTO_CLOSESOCKET()
	{
		if( NULL != m_pSocket && NULL != *m_pSocket )
		{
			closesocket(*m_pSocket);
			*m_pSocket = NULL;
		}
	}
	SOCKET *m_pSocket;
};

struct TG_AUTO_WSACLOSEEVENT
{
	TG_AUTO_WSACLOSEEVENT(WSAEVENT *pEvent)
	{
		m_pEvent = pEvent;
	}
	~TG_AUTO_WSACLOSEEVENT()
	{
		if( NULL != m_pEvent && NULL != *m_pEvent )
		{
			WSACloseEvent(*m_pEvent);
			*m_pEvent = NULL;
		}
	}
	WSAEVENT *m_pEvent;
};


#endif
